// collider.cpp
#include "collider.h"
void collider::render()
{
#ifdef DEBUG_MODE
    node_affiliate::render();
    auto pos = parent_->getRenderPosition() + offset_;
    game_.renderFillCircle(pos, size_, 0.3);
#endif // DEBUG_MODE
}

collider *collider::createCollider(screen *parent, glm::vec2 size, Type type,const char* name,Anchor anchro)
{
    auto collider_ = new collider();
    collider_->init();
    collider_->setAnchor(anchro);
    collider_->setParent(parent);
    collider_->setSize(size);
    collider_->setType(type);
    collider_->name_ = name;
    if(parent)
        parent->addChild(collider_);
    return collider_;
}

bool collider::isColliding(collider *other)
{
    if (!other) return false;
    if (type_ == Type::CIRCLE && other->type_ == Type::CIRCLE)      // 两个圆的情况
    {
        auto point1 = parent_->getWorldPosition() + offset_ + size_ / 2.0f;
        auto point2 = other->parent_->getWorldPosition() + other->offset_ + other->size_ / 2.0f;
        return glm::length(point1 - point2) < (size_.x + other->size_.x) / 2.0f;
    }
    SDL_Log("collider::isColliding: not implemented\n");
    // TODO： 其它形状的碰撞检测 
    return false;
}